//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by LCH on 16/3/4.
//  Copyright © 2016年 lch. All rights reserved.
//

import UIKit


extension UIBarButtonItem {

    convenience init(imageName:String? = nil, title:String? = nil, target: AnyObject?, action: Selector) {
    
      self.init()
        
      let button = UIButton()
        
      button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let t = title {
        
          button.setTitle(t, forState: UIControlState.Normal)
          button .setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
          button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
          button.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        }
        if let name = imageName {
        
            button.setImage(UIImage(named:name), forState:UIControlState.Normal)
            button.setImage(UIImage(named:"\(name)_highlighted"), forState:UIControlState.Highlighted)
            
            
        
        }
        button.sizeToFit()
        customView = button
       
    
    }


}
